<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>收银员</title>
		<link rel="stylesheet" href="__AGENT__/css/css.css" />
		<script type="text/javascript" src="__PUBLIC__/static/js/jquery.min.js"></script>
		<link rel="stylesheet" href="__PUBLIC__/static/layui/css/layui.css">
		<script src="__PUBLIC__/static/layui/layui.js"></script>
		<style type="text/css">
			#sfz_pic{position: relative;}/*opacity: 0;*/
			 .upload,.upload1{position: absolute;top: 0;left: 0;width: 100%;height: 100%;opacity: 0;}
		</style>
	</head>

	<body>
		<form class="layui-form update_form">
			<div class="layui-form-item">
				<label class="layui-form-label">头像</label>
    			<div class="renz_img " id="yyzz_pic">
    				<input type="hidden" name="logo" id="thumb_1" value="{if strlen($data.logo)>2}{$data.logo}{else}__LOGO__/1/logo.png{/if}"  lay-verify="required" autocomplete="off" class="layui-input"/>
    				<input type="file" style="width: 50%;height: 30%;" id="upload_1" class="upload1" value="选择图片文件" multiple />
    				{if condition="$data.logo == null"}
						<span><img class='img_1' id='img_1' style="width: 100px;height: 100px;" src="__LOGO__/1/logomr.png"></span>
					{else /}
						<span><img class='img_1' id='img_1' src="{$data.logo}" style="width: 100px;height: 100px;"></span>
					{/if}
    			</div>
			</div> 
			<div class="layui-form-item">
				<label class="layui-form-label">收银员编号</label>
				<div class="layui-input-block update_shurk">
					<input type="text" name="id" style="display: none;" value="{$data.id}">
					<input type="text" name="no" value="{$data.no}" required lay-verify="required" placeholder="收银员编号" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">收银员电话</label>
				<div class="layui-input-block update_shurk">
					<input type="tel" name="mobile" value="{$data.mobile}" required lay-verify="phone" placeholder="收银员电话" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">收银员姓名</label>
				<div class="layui-input-block update_shurk">
					<input type="text" name="name" value="{$data.name}" required lay-verify="required" placeholder="收银员姓名" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">登录密码</label>
				<div class="layui-input-block update_shurk">
					<input type="password" name="password"  placeholder="登录密码" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">类型</label>
				<div class="layui-input-block">
					<input type="radio" name="ctype" value="1" title="收银员" {if condition="$data['ctype'] eq 1 " }checked{/if}>
					<input type="radio" name="ctype" value="2" title="店长"  {if condition="$data['ctype'] eq 2 " }checked{/if}>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">状态</label>
				<div class="layui-input-block">
					<input type="radio" name="state" value="1" title="在职" {if condition="$data['state'] eq 1 " }checked{/if}>
					<input type="radio" name="state" value="2" title="离职" {if condition="$data['state'] eq 2 " }checked{/if}>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">归属门店</label>
				<div class="layui-input-block" style="float: left; margin-right: 20px; margin-left: 0;">
					<select name="chain_id" lay-verify="required">
						{volist name="typelist" id="vo"}
						<option value="{$vo.id}" {if condition="$data.chain_id==$vo.id" } selected="selected" {/if}>{$vo.store_name}</option>
						{/volist}
					</select>
				</div>
			</div>
			<div class="layui-form-item update_btnbox">
				<div class="layui-input-block">
					<button class="layui-btn" lay-submit lay-filter="submit_from"  type="button" >立即提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</form>
	</body>
</html>
<script>
//图片上传
layui.use(['form','upload'], function(){
	var $ = layui.jquery,upload = layui.upload,form = layui.form;
	
	//监听表单提交
	form.on('submit(submit_from)', function(data){
		tijiao();
  		return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
	});
	
	var uploadInst_1 = upload.render({
		elem: '#upload_1'
	    ,auto: false //选择文件后不自动上传
	    ,choose: function(obj){
		    //将每次选择的文件追加到文件队列
		    var files = obj.pushFile();
		    //预读本地文件，如果是多文件，则会遍历。(不支持ie8/9)
		    obj.preview(function(index, file, result){
		    	$('#img_1').attr('src', result); //图片链接（base64）
		    	var sendData = result.substring(result.indexOf(";base64,")+8);
		    	$.post("{:url('agent/index/upload')}",{value:sendData},function(data){ 
                            if(data.code == '200'){  
                            	$('#thumb_1').val(data.url);
                            }else{  
                                layer.msg(data.msg);
                            }  
                		});
		    });
		}
	    ,url: "{:url('agent/index/upload')}"
	    ,accept:'images'
	});
});

function tijiao() {
$.ajax({
	type: "post",
	url: "{:url('store/cashier_edit')}",
	data: $('.layui-form').serialize(), //表单数据
	success: function(data) {
		if(data.code == 200) {
			layer.msg('修改成功', {
				icon: 1,
				time: 1500 //2秒关闭（如果不配置，默认是3秒）
			}, function() {
				window.parent.location.reload();
				var index = parent.layer.getFrameIndex(window.name); //获取窗口索引  
				parent.layer.close(index);
			});
		} else {
			layer.msg('修改失败！'); //保存成功提示
			}
		},
		error: function(data) {
			var a = data;
		}
	});

}
</script>